﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace DivingTypesFileRead
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader("hopp2.txt");

            string line;

            List<DivingType> DivingTypeList = new List<DivingType>();

  
            
            while (!sr.EndOfStream)
            {
                DivingType Temp = new DivingType();

                line = sr.ReadLine();

                string[] sp = line.Split('\t');

                sp[1] = sp[1].Remove(sp[1].Length - 1);

                int TempIntHeight = Convert.ToInt16(sp[1]);
                double TempDoubleConstant = Convert.ToDouble(sp[3], System.Globalization.CultureInfo.InvariantCulture);

                
                //Seach through the entire list d for previous occurances of the sp[0] ID.
                //If a previous one was found, just add the newly found height and constant to its list.
                Boolean HeightConstantAdded = false;
                foreach (var TempTemp in DivingTypeList)
                {
                    if (TempTemp.ID == sp[0])
                    {
                        TempTemp.AddHeight(TempIntHeight);
                        TempTemp.AddConstant(TempDoubleConstant);

                        HeightConstantAdded = true;
                        break;
                    }
                }

                
                //This if handles the situation where a entierly new object must be added to the list.
                if (!HeightConstantAdded)
                {
                    Temp.ID = sp[0];
                    Temp.AddHeight(TempIntHeight);
                    Temp.TypeName = sp[2];
                    Temp.AddConstant(TempDoubleConstant);
                    DivingTypeList.Add(Temp);
                }
            }

            foreach (var Pryl in DivingTypeList)
            {
                Console.WriteLine(Pryl.TypeName);
            }


            Console.ReadKey();


        }
    }
}
